<template>
	<view class="pd pt60 pm120">
		<view class="formrow">
			<view class="z9 fz28">
				副钥匙账户
			</view>
			<view class="mt20 pr">
				<!-- <input type="text" value="" placeholder="请输入对方账户" class="jhhgerttyt" v-model="from.jhhgdfa"/> -->
				<view class="jhhgerttyt">{{keysinfo.phone}}</view>
			</view>
		</view>
		<view class="formrow mt70">
			<view class="z9 fz28">
				名称备注
			</view>
			<view class="mt20 pr">
				<input type="text" value="" placeholder="请设置对方备注" class="jhhgerttyt" v-model="keysinfo.name" />
			</view>
		</view>
		<view class="formrow mt70">
			<view class="z9 fz28">
				起止时间
			</view>
			<view class="mt20 pr jhhgerttyt row z9 dfgryusr cen">
				<view class="col fz24">
					<!-- <text v-if="from.jhhgdfc">{{from.jhhgdfc}}</text>
					<text v-else class="z9">开始时间 </text> -->
					<view class="z9">{{keysinfo.begin_time}}</view>
				</view>
				<view class="hhgxeer">

				</view>
				<view class="col fz24">
					<!-- <text v-if="from.jhhgdfd">{{from.jhhgdfd}}</text>
					<text v-else class="z9">结束时间 </text> -->
					<view class="z9">{{keysinfo.end_time}}</view>
				</view>
			</view>
		</view>

		<view class="formrow mt70">
			<view class="z9 fz28">
				权限授权
			</view>
			<view class="mt20 pr parent">
				<view class="kjhnderty yj4 pr" :class="sd.cls" v-for="sd in sqssf">
					<icon type="success" size="18" color="#fff" class="dsfrtyswr" />
					<view class="jjhdertt cen">
						<image :src="'../../static/img/AddViceKey/'+sd.icon" class="jhhdrettw cz" :class="sd.classname" mode="widthFix"></image>
					</view>
					<view class="fz26 cen" v-if="sd.id==3" style="color: #747474;">{{sd.name}}</view>
					<view class="cf fz26 cen" v-if="sd.id!=3">{{sd.name}}</view>
				</view>
			</view>
		</view>

		<view class="mt120 jjhhxeerts">
			<!-- <text v-if="isjihuo==0">立即激活</text> -->
			<text v-if="keysinfo.status==1" @tap="jinkey">禁用副钥匙</text>
			<text v-if="keysinfo.status==0" @tap="jihuokey">启用副钥匙</text>
			<!-- <text v-if="isjihuo==2">激活副钥匙</text> -->
		</view>
		<view class="fz36 ls cen mt20" @tap="delkey">
			删除副钥匙
		</view>
		
		
	</view>
</template>
<script>
	export default {
		data() {
			return {
				userdata:[],
				num:"",
				from: {
					jhhgdfa: '',
					jhhgdfb: '',
					jhhgdfc: '',
					jhhgdfd: '',
					rulesnum:0,
					userid:0
				},
				userid:0,
				devsn:0,
				islinuser:false,
				sqssf: [{
						id:"1",
						icon: 'kjjhfc.png',
						classname: '',
						name: '开关锁',
						cls: '',
						ruleid:1,
						color:'#fff'
					},
					{
						id:"2",
						icon: 'kjjhfd.png',
						classname: 'ab',
						name: '启动熄火',
						cls: '',
						ruleid:2,
						color:'#fff'
					},
					{
						id:"3",
						icon: 'kjjhfe.png',
						classname: 'ac',
						name: '分发副钥匙',
						cls: '',
						ruleid:0,
						color:'#eee'
					},
					{
						id:"4",
						icon: 'kjjhff.png',
						classname: 'ad',
						name: '远程控制',
						cls: '',
						ruleid:4,
						color:'#fff'
					},
					{
						id:"5",
						icon: 'kjjhfg.png',
						classname: 'ae',
						name: '实时位置',
						cls: '',
						ruleid:0,
						color:'#fff'
					},
					{
						id:"6",
						icon: 'kjjhfh.png',
						classname: 'af',
						name: '临时授权',
						cls: '',
						ruleid:2000,
						color:'#fff'
					}
				],
				isjihuo: 0, // 激活的状态				
				keysid: 0 ,// 副钥匙id				
				keysauthid: 0, // 副钥匙设备授权id				
				istype: 0, // 0 新增 1 查看详情		
				keysinfo:{}
			}
		},
		components: {},
		computed: {
			indicatorStyle() {
				return {
					background: 'rgba(0,0,0,0.1)',
					height: '40px',
				};
			}
		},
		methods: {
			kjssf(datas) {
				console.log(datas);
				var strs= new Array(); //定义一数组 
				strs=datas.split(","); //字符分割 
				strs.map(b=>{
					let key = b-1
					this.sqssf[key].cls = "act"
				})
			},
			delkey() {
				// 删除副钥匙
				let that = this
				
				uni.showModal({
				    title: '提示',
				    content: '是否确认删除副钥匙',
				    success: function (res) {
				        if (res.confirm) {
				            that.dqDelAuthKey(that.keysinfo.authid,(e)=>{
				            	// 撤销授权
								// uni.showModal({
									
								// 	content:JSON.stringify(e)
								// 	// icon:"none"
								// }) 
				            	// let isdeldata = e.data
				            	// if(e.success){
				            		let params={}
				            		let still= that.get('/api/car_key/key/'+that.keysinfo.id+'/type/1',params,"DELETE")
								// uni.showToast({
								// 	title:JSON.stringify(still),
								// 	icon:"none"
								// })
				            		// if(still.code==0){
				            			uni.showToast({
				            				title: '删除成功！',
				            				success() {
												setTimeout(function(){
													uni.navigateBack({
														delta:2
													})
												},1500)
				            				}
				            			})	
				            		// }
				            	// }else{
				            	// 	uni.showToast({
				            	// 		title:e.message,
				            	// 		icon:"none"
				            	// 	})
				            	// }
				            })
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
				
			},
			jinkey(){
				let that=this
				uni.showModal({
				    title: '提示',
				    content: '是否确认禁用副钥匙',
				    success: function (res) {
				        if (res.confirm) {
							let params = {}
				            let still= that.get('/api/car_key/key/'+that.keysinfo.id+'/type/1',params,"PUT")
							uni.showToast({
								title:"禁用成功",
								icon:"none"
							})
							setTimeout(function(){
								uni.navigateBack({
									delta:2
								})
							},1500)
				            // if(still.code==0){
				            	// uni.showToast({
				            	// 	title: '禁用成功！',
				            	// 	success() {
				            	// 		uni.navigateBack({
				            	// 			delta:1
				            	// 		})
				            	// 	}
				            	// })	
				            // }
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
				
			},
			
			jihuokey(){
				
				let that=this
				let params= {}
				let still= that.get('/api/car_key/key/'+that.keysinfo.id+'/type/1/activate',params,"PUT")
				// if(still.code==0){
					uni.showToast({
						title:"启用成功",
						icon:"none"
					})
					setTimeout(function(){
						uni.navigateBack({
							delta:2
						})
					},1500)
				// }
			},
			async carkeysinfo() {
				// 副钥匙详情
				let params = {}
				params.id = this.keysid
				 let keysinfo=await this.get('/api/car_key/detail/'+this.keysid)
				 this.keysinfo = keysinfo.data
				 this.kjssf(keysinfo.data.rule)
				 console.log(this.keysinfo);
			},
			sancu() {
				uni.showModal({
					title: '',
					content: '您确定删除该账户副钥匙吗？',
					confirmColor: '#fC5A5A',
					confirmText: '删除'
				})
			}			
		},		
		onLoad(options) {
			console.log(options);
			let current = uni.getStorageSync('current')
			console.log(current);
			var th=this
			this.carid=options.carid
			this.devsn=current.data.devsn
			this.istype = options.type
			if(options.hasOwnProperty('keysid')){
				this.keysid  = options.keysid
			}
			if(this.istype ==1){
				//查看详情
				this.carkeysinfo()
			}
		},	
		mounted() {}
	}
</script>
<style scoped>
	
</style>
